/**
 * Created by register on 2017/8/30.
 */
$(function () {
    new AjaxUpload('#upload', {
        action: '/upload',
        name: 'file',
        autoSubmit: true,
        responseType: "json",
        onSubmit: function (file, extension) {
            if (!(extension && /^(xlsx)$/.test(extension.toLowerCase()))) {
                alert('只支持xlsx格式的文件！');
                return false;
            }
        },
        onComplete: function (file, r) {
            if (r.code == 0) {
                vm.msg = '文件上传完成，开始处理';
                vm.errorList = [];
            } else {
                alert(r.msg);
            }
        }
    });
    vm.loadInfo();
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        msg : '',
        errorList : []
    },
    methods: {
        loadInfo : function () {
            $.ajax({
                url : "../info?"+"t="+$.now(),
                type : 'GET',
                success : function (result) {
                    vm.msg = result.msg;
                    vm.errorList = result.errorList;
                },
                error : function () {
                    vm.msg = '系统正在更新，请等待服务恢复正常';
                },
                complete:function(){
                    setTimeout( function () {
                        vm.loadInfo();
                    },3000);
                }
            })
        }
    }
});